package net.pimpas.security.serviceprovider.auth.login.callback.password;

import net.pimpas.security.serviceprovider.auth.login.callback.Callback;

public class PasswordCallback implements Callback, java.io.Serializable {

	private static final long serialVersionUID = 3028736346535087864L;
	private String prompt;
	private boolean echoOn;
	private char[] inputPassword;

	public PasswordCallback(String prompt, boolean echoOn) {
		if (prompt == null || prompt.length() == 0)
			throw new IllegalArgumentException();

		this.setPrompt(prompt);
		this.setEchoOn(echoOn);
	}

	public String getPrompt() {
		return this.prompt;
	}

	public boolean isEchoOn() {
		return this.echoOn;
	}

	public void setPassword(char[] password) {
		this.setInputPassword((password == null ?
				null : (char[])password.clone()));
	}

	public char[] getPassword() {
		return (inputPassword == null?
				null : (char[])inputPassword.clone());
	}

	public void clearPassword() {
		if (this.getPassword() != null) {
			for (int i = 0; i < this.getPassword().length; i++)
				this.getPassword()[i] = ' ';
		}
	}

	public char[] getInputPassword() {
		return this.inputPassword;
	}

	public void setInputPassword(char[] inputPassword) {
		this.inputPassword = inputPassword;
	}

	public void setEchoOn(boolean echoOn) {
		this.echoOn = echoOn;
	}

	public void setPrompt(String prompt) {
		this.prompt = prompt;
	}
}